<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book reacjs开发 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>JSX语法 | reacjs开发</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
    

        
    
    
    <link rel="next" href="../001day/section04.html" />
    
    
    <link rel="prev" href="../001day/section02.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="1.3"
        data-chapter-title="JSX语法"
        data-filepath="001day/section03.md"
        data-basepath=".."
        data-revision="Sun Feb 16 2020 11:31:01 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="001day/index.html">
            
                
                    <a href="../001day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        react入门
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="001day/section01.html">
            
                
                    <a href="../001day/section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        react介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="001day/section02.html">
            
                
                    <a href="../001day/section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        快速开始
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="1.3" data-path="001day/section03.html">
            
                
                    <a href="../001day/section03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        JSX语法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="001day/section04.html">
            
                
                    <a href="../001day/section04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        函数组件和参数props
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="001day/section05.html">
            
                
                    <a href="../001day/section05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        ES6语法之类和类的继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="001day/section06.html">
            
                
                    <a href="../001day/section06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        类组件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="001day/section07.html">
            
                
                    <a href="../001day/section07.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        绑定事件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="001day/section08.html">
            
                
                    <a href="../001day/section08.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.8.</b>
                        
                        状态(state)
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="002day/index.html">
            
                
                    <a href="../002day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        react进阶
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="002day/section01.html">
            
                
                    <a href="../002day/section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        新增数组方法、属性表达式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="002day/section02.html">
            
                
                    <a href="../002day/section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        列表渲染
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="002day/section03.html">
            
                
                    <a href="../002day/section03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        条件渲染
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="002day/section04.html">
            
                
                    <a href="../002day/section04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        表单数据绑定
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="002day/section05.html">
            
                
                    <a href="../002day/section05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        Refs操作元素，文件上传
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="002day/section06.html">
            
                
                    <a href="../002day/section06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        生命周期方法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="003day/index.html">
            
                
                    <a href="../003day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        脚手架开发
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="003day/section01.html">
            
                
                    <a href="../003day/section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        yarn的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="003day/section02.html">
            
                
                    <a href="../003day/section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        脚手架开发
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="004day/index.html">
            
                
                    <a href="../004day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        react高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="004day/section01.html">
            
                
                    <a href="../004day/section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        js模块化开发
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="004day/section02.html">
            
                
                    <a href="../004day/section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        数据传递
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="004day/section03.html">
            
                
                    <a href="../004day/section03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        拆分组件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="004day/section04.html">
            
                
                    <a href="../004day/section04.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        组件children属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="004day/section05.html">
            
                
                    <a href="../004day/section05.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        props校验
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="004day/section06.html">
            
                
                    <a href="../004day/section06.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        props默认值
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="004day/section07.html">
            
                
                    <a href="../004day/section07.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        render-props模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="004day/section08.html">
            
                
                    <a href="../004day/section08.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        高阶组件(HOC)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="004day/section09.html">
            
                
                    <a href="../004day/section09.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        组件更新机制及性能优化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="004day/section10.html">
            
                
                    <a href="../004day/section10.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        虚拟dom及diff算法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="005day/index.html">
            
                
                    <a href="../005day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        react深入
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="005day/section01.html">
            
                
                    <a href="../005day/section01.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        react路由
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="005day/section02.html">
            
                
                    <a href="../005day/section02.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        redux
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="005day/section03.html">
            
                
                    <a href="../005day/section03.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        react-redux
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >reacjs开发</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h2 id="jsx&#x8BED;&#x6CD5;">JSX&#x8BED;&#x6CD5;</h2>
<p>jsx&#x8BED;&#x6CD5;&#x662F;&#x4E00;&#x79CD;&#x7C7B;&#x4F3C;&#x4E8E;html&#x6807;&#x7B7E;&#x7684;&#x8BED;&#x6CD5;&#xFF0C;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x76F8;&#x5F53;&#x4E8E;&#x662F;&#x8BA9;&#x6211;&#x4EEC;&#x5728;JavaScript&#x4EE3;&#x7801;&#x4E2D;&#x76F4;&#x63A5;&#x5199;html&#x4EE3;&#x7801;&#xFF0C;&#x4F46;&#x662F;jsx&#x4E0D;&#x5B8C;&#x5168;&#x662F;html&#xFF0C;&#x5B83;&#x662F; JavaScrip &#x7684;&#x4E00;&#x79CD;&#x6269;&#x5C55;&#x8BED;&#x6CD5;&#xFF0C;&#x5B83;&#x5177;&#x6709; JavaScript &#x7684;&#x5168;&#x90E8;&#x80FD;&#x529B;&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x5728;jsx&#x4EE3;&#x7801;&#x4E2D;&#x63D2;&#x5165;&#x53D8;&#x91CF;&#x6216;&#x8005;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x7528;jsx&#x8BED;&#x6CD5;&#x5199;&#x51FA;&#x6765;&#x7684;&#x8BED;&#x53E5;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C06;&#x5B83;&#x5B58;&#x4E3A;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x4F5C;&#x4E3A;ReactDOM&#x5BF9;&#x8C61;&#x7684;render&#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> el = <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-title">h1</span>&gt;</span>Hello world!<span class="hljs-tag">&lt;/<span class="hljs-title">h1</span>&gt;</span>;</span>
ReactDOM.render(
    el,
    <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&apos;root&apos;</span>)
)
</code></pre>
<p>doucument.getElementById(&apos;root&apos;);</p>
<h4 id="&#x57FA;&#x672C;&#x8BED;&#x6CD5;&#x793A;&#x4F8B;">&#x57FA;&#x672C;&#x8BED;&#x6CD5;&#x793A;&#x4F8B;</h4>
<p>jsx&#x7684;&#x7ED3;&#x6784;&#x8FD8;&#x53EF;&#x4EE5;&#x5199;&#x5F97;&#x66F4;&#x590D;&#x6742;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x5D4C;&#x5957;&#x7ED3;&#x6784;&#xFF0C;&#x5982;&#x679C;&#x662F;&#x5D4C;&#x5957;&#x7ED3;&#x6784;&#xFF0C;&#x9700;&#x8981;&#x6709;&#x552F;&#x4E00;&#x7684;&#x4E00;&#x4E2A;&#x5916;&#x5C42;&#x6807;&#x7B7E;&#x3002;&#x6807;&#x7B7E;&#x4E2D;&#x5982;&#x679C;&#x662F;&#x5355;&#x4E2A;&#x7684;&#x6807;&#x7B7E;&#xFF0C;&#x5728;&#x7ED3;&#x5C3E;&#x8981;&#x52A0;&#x201C;/&#x201D;,&#x5728;jsx&#x4E2D;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x201C;{}&#x201D;&#x63D2;&#x5165;&#x53D8;&#x91CF;&#xFF0C;&#x8868;&#x8FBE;&#x5F0F;&#x6216;&#x8005;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x3002;</p>
<pre><code class="lang-javascript">&lt;script type=&quot;text/babel&quot;&gt;
    let iNum01  = 10;
    let sTr = &apos;abc123456&apos;;
    function fnRev(s){
        return s.split(&apos;&apos;).reverse().join(&apos;&apos;);
    }    
    let el = (
        &lt;div&gt;
            {/* jsx&#x6CE8;&#x91CA;&#x5B9A;&#x4E49;&#x65B9;&#x6CD5; */}
            &lt;h3&gt;jsx&#x8BED;&#x6CD5;&lt;/h3&gt;
            {/* &#x63D2;&#x5165;&#x53D8;&#x91CF;&#x53CA;&#x8FD0;&#x7B97; */}
            &lt;p&gt;{ iNum01+5 }&lt;/p&gt;
            {/* &#x63D2;&#x5165;&#x8868;&#x8FBE;&#x5F0F; */}
            &lt;p&gt;{ sTr.split(&apos;&apos;).reverse().join(&apos;&apos;) }&lt;/p&gt;
            {/* &#x63D2;&#x5165;&#x51FD;&#x6570;&#x8C03;&#x7528; */}
            &lt;p&gt;{ fnRev(sTr) }&lt;/p&gt;
            {/* &#x63D2;&#x5165;&#x4E09;&#x5143;&#x8FD0;&#x7B97;&#x8868;&#x8FBE;&#x5F0F; */}
            &lt;p&gt;{ ok?&apos;YES&apos;:&apos;NO&apos; }&lt;/p&gt;                
        &lt;/div&gt;
    );

    ReactDOM.render(
        el,
        document.getElementById(&apos;root&apos;)
    )

&lt;/script&gt;
</code></pre>
<h4 id="&#x6807;&#x7B7E;&#x5C5E;&#x6027;&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;">&#x6807;&#x7B7E;&#x5C5E;&#x6027;&#x5B9A;&#x4E49;&#x65B9;&#x6CD5;</h4>
<p>jsx&#x4E2D;&#x6307;&#x5B9A;&#x6807;&#x7B7E;&#x7684;&#x5C5E;&#x6027;&#x503C;&#x5EFA;&#x8BAE;&#x7528;&#x53CC;&#x5F15;&#x53F7;&#xFF0C;&#x4E0D;&#x80FD;&#x4E0D;&#x7528;&#x5F15;&#x53F7;&#xFF0C;&#x5176;&#x4E2D;class&#x5C5E;&#x6027;&#x9700;&#x8981;&#x5199;&#x6210;className&#xFF0C;&#x5C5E;&#x6027;&#x503C;&#x5982;&#x679C;&#x662F;&#x53EF;&#x53D8;&#x7684;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5199;&#x6210;&#x201C;{}&#x201D;&#x7684;&#x5F62;&#x5F0F;&#xFF0C;&#x91CC;&#x9762;&#x53EF;&#x4EE5;&#x548C;&#x4E0A;&#x9762;&#x5199;&#x6CD5;&#x4E00;&#x6837;&#x3002; &#x6807;&#x7B7E;&#x5982;&#x679C;&#x662F;&#x5355;&#x4E2A;&#x7684;&#xFF0C;&#x5728;&#x7ED3;&#x5C3E;&#x4E00;&#x5B9A;&#x8981;&#x52A0;&#x201C;/&#x201D; </p>
<pre><code class="lang-javascript">{/* &#x5B9A;&#x4E49;class */}
&lt;p className=&quot;sty01&quot;&gt;&#x4F7F;&#x7528;&#x6837;&#x5F0F;&lt;/p&gt;
{/* &#x5355;&#x4E2A;&#x6807;&#x7B7E;&#xFF0C;&#x7ED3;&#x5C3E;&#x8981;&#x52A0;&#x201C;/&#x201D; */}
&lt;img src={user.avatarUrl} /&gt;
</code></pre>
<h4 id="&#x4F7F;&#x7528;&#x884C;&#x95F4;&#x6837;&#x5F0F;">&#x4F7F;&#x7528;&#x884C;&#x95F4;&#x6837;&#x5F0F;</h4>
<p>&#x884C;&#x95F4;&#x6837;&#x5F0F;&#x4E00;&#x822C;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#xFF0C;&#x4F46;&#x662F;&#x6709;&#x7684;&#x7EC4;&#x4EF6;&#x7ED3;&#x6784;&#x4E2D;&#x4F1A;&#x5C11;&#x91CF;&#x7528;&#x5230;&#xFF0C;&#x5B9A;&#x4E49;&#x7684;&#x65B9;&#x5F0F;&#x662F;&#x5728;&#x201C;{}&#x201D;&#x4E2D;&#xFF0C;&#x5C06;&#x6837;&#x5F0F;&#x5C5E;&#x6027;&#x5199;&#x6210;&#x5BF9;&#x8C61;&#x7684;&#x952E;&#x503C;&#x5BF9;&#x5F62;&#x5F0F;&#xFF0C;&#x503C;&#x53EF;&#x4EE5;&#x4E0D;&#x52A0;&#x5355;&#x4F4D;&#xFF0C;&#x76F4;&#x63A5;&#x5199;&#x6210;&#x6570;&#x5B57;&#xFF0C;&#x5E26;&#x201C;-&#x201D;&#x7684;&#x5C5E;&#x6027;&#x540D;&#x8981;&#x5199;&#x6210;&#x9A7C;&#x5CF0;&#x5F0F;&#x3002;</p>
<pre><code> &lt;p style={{width:&apos;300px&apos;,height:200,color:&apos;#ddd&apos;,backgroundColor:&apos;hotpink&apos;}}&gt;&#x8FD9;&#x662F;&#x4E00;&#x4E2A;&#x4F7F;&#x7528;style&#x6837;&#x5F0F;&#x7684;&#x6BB5;&#x843D;&lt;/p&gt;
</code></pre>
                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../001day/section02.html" class="navigation navigation-prev " aria-label="Previous page: 快速开始"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../001day/section04.html" class="navigation navigation-next " aria-label="Next page: 函数组件和参数props"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/fontsettings.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"fontsettings":{"family":"sans","size":2,"theme":"white"},"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book reacjs开发 -->
</html>
